/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.*;

/**
 * <p>Project: javase - File4
 * <p>Powered by webrx On 2021-12-14 09:36:06
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class File4 {
    public static void main(String[] args) {

        //读取数据
        //InputStream is = new FileInputStream("y.txt");

        //写入数据
        //OutputStream os = new FileOutputStream("y.txt",true);


        //字节流写入读取 文本文件 ascii文件
        try (var fos = new FileOutputStream("a.txt", true); var fis = new FileInputStream("a.txt")) {
            //写文件 "a.txt",true 此处的代表append追加模式，如果文件不存在直接建立写入，如果文件存在，将文件指针移动文件尾，写入内容
            fos.write("中文字符串\r\n".getBytes());
            //读取文件
            System.out.println(new String(fis.readAllBytes()));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        byte[] buf = new byte[1024];
        try (var fos = new FileOutputStream("c:/wx.jpg");) {
            fos.write(buf); //
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
